<%@ Page Language="vb" AutoEventWireup="false"  CodeFile="ItemSearch.aspx.vb" Inherits="ItemSearch" title="Item Search"  MasterPageFile="~/site.master"%>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {

        });

        function RunSearch() {
            $("#grid1").jqGrid({
                datatype: 'local',
                width: 940,
                colNames: ['ID', 'Part #', 'Description', 'MFG #', 'QTY'],
                colModel: [
               		{ name: 'ID', index: 'ID', hidden: true },
                    { name: 'PartNumber', index: 'PartNumber', width: 25, align: 'left' },
               		{ name: 'Description', index: 'Description' },
               		{ name: 'MFGNumber', index: 'MFGNumber', width: 25, align: 'center' },
               		{ name: 'Quantity', index: 'Quantity', width: 15, sorttype: 'int', align: 'center' }
               	],
                sortable: true,
                altRows: true,
                viewrecords: true,
                altclass: "ITrackerGridViewRowAlternate",
                onSelectRow: function (id) {
                    var rowData = $(this).getRowData(id);
                    var temp = rowData["ID"];
                    location.href = 'Item/' + temp;
                }
                
            });
            $("#grid1").clearGridData();
            getGridData();
        }
        function getGridData() {
            // a=desc, b=partnum, c=mfgnum, d=vendID
            var vID = $("#<%=ddlVendor.ClientID %> option:selected").val();
            $.ajax({
                type: "POST",
                url: "ItemSearch.aspx/GetDataForGrid",
                data: "{a: '" + $("#<%=txtDesc.ClientID %>").val() + "',b:'" + $("#<%=txtPartNum.ClientID %>").val() + "',c:'" + $("#<%=txtMFGNum.ClientID %>").val() + "',d:'" + vID + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data, textStatus) {
                    if (textStatus == "success") {
                        for (var i = 0; i <= data.d.length - 1; i++)
                             $("#grid1").addRowData(i, data.d[i]);
                    }
                },
                error: function () {
                    alert("Error with AJAX callback");
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h2><asp:label ID="lblPageHeader" runat="server" CssClass="PageHeader"></asp:label></h2>
    <table>
        <tr>
            <td align="right"><b>Description:</b></td>
            <td><asp:TextBox  CssClass="ITrackerTextBox" ID="txtDesc" runat="server"></asp:TextBox></td>
            <td align="right"><b>Vendor:</b></td>
            <td><asp:DropDownList CssClass="ITrackerDropDownList" id="ddlVendor" runat="server"></asp:DropDownList></td>
        </tr>
        <tr>
            <td align="right"><b>Part#:</b></td>
            <td><asp:TextBox  CssClass="ITrackerTextBox" ID="txtPartNum" runat="server"></asp:TextBox></td>
            <td align="right"><b>MFG#</b></td>
            <td><asp:TextBox  CssClass="ITrackerTextBox" ID="txtMFGNum" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td colspan="4" align="right"><input type="button" value="Search" onclick="RunSearch();" /></td>
        </tr>
    </table>  
    <br />
    <table id="grid1" class="ITrackerGridView"></table>
</asp:Content>
